const app = new Vue({
    el: '#app',
    data: {
        books: [{
                id: 1,
                name: '《计算机导论》',
                date: '2009',
                price: 20.00,
                count: 2
            },
            {
                id: 2,
                name: '《JavaWeb从入门到入土》',
                date: '2029',
                price: 30.00,
                count: 2
            },
            {
                id: 3,
                name: '《Vue.js前端教程》',
                date: '2015',
                price: 40.00,
                count: 2
            },
            {
                id: 4,
                name: '《谁杀了她》',
                date: '2009',
                price: 50.00,
                count: 2
            }
        ]
    },
    methods: {
        //移除书籍
        removeBook(index) {
            this.books.splice(index, 1);
        },
        // 计算每种书的小计价格
        xiaoJi(index) {
            let xiaoJi = 0;
            xiaoJi += this.books[index].count * this.books[index].price;
            return xiaoJi;
        }
    },
    computed: {
        totalPrice: {
            get() {
                let total = 0;
                for (let i = 0; i < this.books.length; i++) {
                    total += this.books[i].price * this.books[i].count
                }
                return total;
            }
        },
    }
})





//编程范式：命令式编程/声明式编程
//编程范式：面向对象编程（第一公民：对象）/函数式编程（第一公民：函数）